package cn.fu.ssh.utils;

import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;
import org.apache.struts2.ServletActionContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import cn.fu.ssh.domain.Employee;
import cn.fu.ssh.service.IEmployeeService;

/**
 * 员工经理任务分配
 *
 */
@SuppressWarnings("serial")
public class ManagerTaskHandler implements TaskListener {
	

	public void notify(DelegateTask delegateTask) {
		//从Session中获取当前用户
		Employee employee = SessionContext.get();
		//获取用户名
		String name = employee.getName();

		//在ManagerTaskHandler类中调用Service（前提：由于web容器启动的时候，已经将spring容器的配置放置到内存中）
		WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(ServletActionContext.getServletContext());
		IEmployeeService employeeService = (IEmployeeService) applicationContext.getBean("employeeService");
		
		//使用用户名作为查询条件，查询用户表，获取用户对象
		Employee emp = employeeService.findEmployeeByName(name);
		
		//指定个人任务的办理人
		delegateTask.setAssignee(emp.getManager().getName());
	}

}
